import { OrderTable } from '@/app/components/orderTable';
import { OrderStore } from '@/app/lib/store/interface/order';
import { Metadata } from 'next';
import { Suspense } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

export const metadata: Metadata = {
  title: '我的订单',
  description: '我的订单',
  openGraph: {
    title: '我的订单',
    description: '探索我们的应用功能',
    url: 'https://your-site.com',
    siteName: '我的应用',
    locale: 'zh_CN',
    type: 'website',
  },
};

const fetchOrderData = async () => {
  try {
    const res = await fetch('http://localhost:3000/api/orders/list');
    if (res.ok) {
      const data: OrderStore.OrderItem[] = await res.json();
      return {
        code: 0,
        data,
      };
    }

    return {
      code: 1,
    };
  } catch (error) {
    return {
      code: 10004,
      error,
    };
  }
};

/**
 * @author        lx <1154354121@qq.com>
 * @date          2025-04-15 08:55:27
 * Copyright © YourCompanyName All rights reserved
 */
export default function Order() {
  // const [list, setList] = useState<OrderStore.OrderItem[]>([]);
  const list = fetchOrderData();

  return (
    <>
      <div>Order</div>
      <ErrorBoundary fallback={<p>error</p>}>
        <Suspense fallback={<p>loading</p>}>
          <OrderTable initialRes={list} />
        </Suspense>
      </ErrorBoundary>
    </>
  );
}
